package com.yyq.thread;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author yyq
 * @create 2021-08-03 11:09
 */
public class Print implements java.lang.Runnable {
    private ReentrantLock lock=new ReentrantLock();
    private int i=0;
    @Override
    public void run() {
        while(true){


            synchronized (this) {
                notify();
                if(i<=100){
                    System.out.println(Thread.currentThread().getName()+"输出:"+i);
                    i++;
                }
                else {
                    break;
                }

                try {
                    wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }


        }

    }


}

class Test{
    public static void main(String[] args) {
        Print t =new Print();
        Thread th1=new Thread(t);
        Thread th2=new Thread(t);
        th1.setName("线程一");
        th2.setName("线程二");
        th1.start();
        th2.start();
    }
}